package com.hbnu.array;

import java.util.Scanner;

/**
 * 计算天数
 *
 * @author chendikai
 * @date 2024-09-11 9:19
 */
public class ArrayDemo06 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入年：");
        int year = scanner.nextInt();
        System.out.println("请输入月：");
        int month = scanner.nextInt();
        System.out.println("请输入日：");
        int day = scanner.nextInt();

        int count = 0;   // 存放指定月份前面几个月的总天数
        int days = 0;  // 用于记录每个月的总天数

        for (int i = 1; i < month; i++) {
            switch (i) {
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                    days = 31;
                    break;
                case 4:
                case 6:
                case 9:
                case 11:
                    days = 30;
                    break;
                case 2:
                    if ((year % 100 != 0 && year % 4 == 0) || (year % 100 == 0 && year % 400 == 0)) {  // 闰年条件
                        days = 29;
                    } else {
                        days = 28;
                    }
                    break;
            }
            count += days;
        }
        System.out.println(year + "年" + month + "月" + day + "日是这一年当中的第" + (count + day) + "天");
    }
}
